package com.ruoyi.apis.service.impl;

import com.ruoyi.apis.entity.OfflineEntity;
import com.ruoyi.apis.entity.OnlineEntity;
import com.ruoyi.apis.repository.OfflineRepository;
import com.ruoyi.apis.service.OfflineService;
import com.ruoyi.apis.service.OnlineService;
import com.ruoyi.apis.vo.OfflineVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Choi
 * @Date 2021/7/19
 */

@Service
public class OfflineServiceImpl implements OfflineService {

    @Autowired
    private OfflineRepository offlineRepository;

    @Override
    public OfflineVO getById(long offlineId) {
        OfflineEntity offlineEntity = offlineRepository.findById(offlineId);
        if (offlineEntity == null) {
            return null;
        }
        return new OfflineVO(offlineEntity);
    }

    @Override
    public Page<OfflineEntity> getOfflines(int page, int size) {
        Pageable pageable = PageRequest.of(page, size);
        return offlineRepository.findAllByOrderBySortAsc(pageable);
    }

    @Override
    public List<OfflineEntity> getByTitle(String title) {
        return offlineRepository.findAllByTitleLikeOrderBySortAsc(title);
    }
}
